﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using ACP.Business;
using ACP.DTO;


namespace ACP.Web.UI
{
    public partial class ActivateUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Lets Activate the User
            if (String.IsNullOrEmpty(Request.QueryString["Id"]))
            {
                // We do not have the userId. Redirect some where
                Response.Redirect("ErrorPage.aspx");
            }
            else
            {
                // We have a userId.
                try
                {
                    Guid userId = new Guid(Request.QueryString["Id"]);
                    MembershipUser user = Membership.GetUser(userId);
                    // Activate the user
                    user.IsApproved = true;
                    // Update the user activation
                    Membership.UpdateUser(user);

                    // We success fully activate the user. Redirect somewhere
                    Response.Redirect("~/Account/Login.aspx?str=Activated&user=" + user.ToString(),false);
                    HttpContext.Current.ApplicationInstance.CompleteRequest();

                }
                catch (Exception ex)
                {
                    acptest_ErrorLog errorLog = new acptest_ErrorLog()
                    {
                        //ex.Message, "Page_Load", "Test Page"
                        ErrorMessage = ex.Message + ex.StackTrace,
                        ErrorFunction = "Page_Load",
                        InsertedTime = DateTime.Now,
                        ModuleName = "ActivateUser.aspx"
                    };
                    ACPErrorLogLogic.ErrorLog(errorLog);
                }
            }
            // We should never reach here. Just in case redirect some where
           // Response.Redirect("Default.aspx", true);
        }

    }
}